<template>
  <div class='content'>
    <div class="profile_page">
      <head-top :go-back='goBack' :head-title="profiletitle"></head-top>
    </div>
    <div class="formContain">
      <titlebar :title-left='titleLeft1'></titlebar>
      <ul>
        <li class="flex">
          <span class="label">申请部门</span>
          <div>
            <span class="vtext">{{datas.startDept}}</span>
          </div>
        </li>
        <li class="flex">
              <span class="label">增补职位</span>
              <div>
                  <span class="vtext">{{datas.addPost}}</span>
              </div>
        </li>
        <li class="flex">
          <span class="label">人数</span>
          <div>
            <span class="vtext">{{datas.perNum}}</span>
          </div>
        </li>
        <li class="flex">
          <span class="label">填表日期</span>
          <div>
            <input type="text"  :value="datas.startDate"  readonly>
            <img src="@/assets/images/img/calendarIcon.png" alt="">
          </div>
        </li>
          <li class="flex">
              <span class="label">机构层级</span>
              <div>
                  <span class="vtext">{{datas.orgLevel}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">需求岗位</span>
              <div>
                  <span class="vtext">{{datas.post}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">职级</span>
              <div>
                  <span class="vtext">{{datas.postRank}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">填补理由</span>
              <div>
                  <span class="vtext">{{datas.addReason}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">岗位职责</span>
              <div>
                  <span class="vtext">{{datas.postDuty}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">希望报到日期</span>
              <div>
                  <input type="text"  :value="datas.wishDate"  readonly>
                  <img src="@/assets/images/img/calendarIcon.png" alt="">
              </div>
          </li>
          <li class="flex">
              <span class="label">性别</span>
              <div>
                  <span class="vtext">{{datas.sex}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">婚姻</span>
              <div>
                  <span class="vtext">{{datas.marriage}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">年龄</span>
              <div>
                  <span class="vtext">{{datas.age}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">学历</span>
              <div>
                  <span class="vtext">{{datas.degree}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">专业</span>
              <div>
                  <span class="vtext">{{datas.major}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">经验要求</span>
              <div>
                  <span class="vtext">{{datas.experience}}</span>
              </div>
          </li>
          <li class="flex">
              <span class="label">技术要求</span>
              <div>
                  <span class="vtext">{{datas.tec}}</span>
              </div>
          </li>
          <!--<li class="flex">
              <span class="label">附件说明</span>
              <div @click="downloadFile('24b6a33ed2c942be94c0046587fff281')">
                  <span class="vtext" >测试附件下载</span>
                  <img src="@/assets/image/ico_down.png" alt="">
              </div>
          </li>

        <li class="flex">
          <span class="label"><i class="require">*</i>审批意见</span>
          <div style="min-height:3rem">
            <van-field class='full_width' autosize v-model="opinion" type="textarea" input-align="right"/>
          </div>
        </li>-->
      </ul>
    </div>
      <div class="formContain">
          <titlebar :title-left='titleLeft2'></titlebar>
          <ul v-if="attachments.length>0">
              <li class="flex" v-for="(item,index) in attachments" :key="item.attachmentId">
                  <span class="label">附件{{index+1}}</span>
                  <div @click="downloadFile(item.attachmentId,item.attachmentName)">
                      <span class="vtext" >{{item.attachmentName}}</span>
                      <img src="@/assets/image/ico_down.png" alt="">
                  </div>
              </li>
              <li class="flex">
                  <span class="label"><i class="require">*</i>审批意见</span>
                  <div style="min-height:3rem">
                      <van-field class='full_width' autosize v-model="opinion" type="textarea" input-align="right"/>
                  </div>
              </li>
          </ul>
          <ul v-if="attachments.length<=0">
              <li class="label" style="text-align: center;line-height: 1rem;font-size: 0.54rem">暂无附件</li>
              <li class="flex">
                  <span class="label"><i class="require">*</i>审批意见</span>
                  <div style="min-height:3rem">
                      <van-field class='full_width' autosize v-model="opinion" type="textarea" input-align="right"/>
                  </div>
              </li>
          </ul>
      </div>
    <div class="align_center foot-button">
      <van-button class="cancel-btn" type="primary" @click="saveData('no')">退回</van-button>
      <van-button class="primary-btn" type="primary" @click="saveData('yes')">同意</van-button>
    </div>
    <van-popup v-model="pickershow" position="bottom">
      <van-picker   show-toolbar  :title="title" :columns="columns" @cancel="onCancel" @confirm="onConfirm"/>
    </van-popup>
    <van-popup v-model="show" position="bottom">
      <van-datetime-picker type="date" @confirm="datetimeSelect" @cancel='cancel' v-model="currentTime"/>
    </van-popup>
      <van-image-preview v-model="previewShow" :images="images"></van-image-preview>
  </div>
</template>

<script>
  var that;
  let Base64 = require('js-base64').Base64
  import headTop from '@/components/header/head'
  import titlebar from '@/components/titlebar3/titlebar3';
  import {getPersonRequireData,submitApply,getAttachment} from '@/service/getData';
  import {setStore,getStore,getDefault,contextRoot} from '@/assets/config/mUtils';
  import {Dialog, Toast} from 'vant';
  import {getUser} from '@/service/getData';

  export default {
    data() {
      return {
        company: "",//所属公司
        profiletitle: '待办事项',
        goBack: true,
        titleLeft: '基本信息',
        titleLeft1: '人员需求信息',
        titleLeft2: '附件信息',
        show: false, //控制日期显示隐藏
        pickershow: false,//控制下拉选显示隐藏
        pickerName: '',//当前控制日期的控件
        currentTime: new Date(),
        title:'标题',//下拉框标题
        fileName: '',
        datas: {
            postDuty:'',
            wishDate:'',
            sex:'',
            degree:'',
            addPost:'',
            startDept :'',
            orgLevel:'',
            perNum:'',
            experience:'',
            postRank:'',
            tec:'',
            major:'',
            post:'',
            marriage:'',
            addReason:'',
            age:'',
            startDate:'',
        },
        partyFigureText: '',
        lookUrl: '',
        useType: 'apply',
        screenHeight: '',
        applyType: '',
        columns:[],
        codeSet:{},
        taskId:'',
        startManagerId:'',
        procInstId:'',
        opinion:'',
        attachments:[],
        previewShow:false,
        images:[]
      }
    },
    created() {
      that = this;
      this.startManagerId = this.$route.query.startManagerId;
      this.taskId = this.$route.query.taskId;
      this.procInstId = this.$route.query.procInstId;
//      this.codeSet = this.$store.state.codeSet;

      var data = {};
      data.app_userId = getStore('user_id');
      data.id = this.startManagerId;
      data.CHECK_TIME = new Date().getTime().toString();
      data.CHECK_SIGN = this.$md5(data.app_userId + data.CHECK_TIME + "3a28fba00c015e0df7f88556c91cb7fc");
        getPersonRequireData(data).then(res => {
        console.log(res);
        this.datas = res.data;

      });
        getAttachment(data).then(res=>{
            console.log(res);
            this.attachments = res.data.data;
        })
    },
    mounted() {
      const _self = this;
      this.screenHeight = document.documentElement.clientHeight;
    },
    components: {
      headTop,
      titlebar,
    },
    updated() {
      let that = this;
    },
    filters:{
      dictNum:function(val,arg1){
        if(val!=""&&val!=undefined&&val!=null){
          if(arg1 == 'getRetireData'){
            var arr = that.useTemp.filter(item=>item.id === val);
//          console.log(val,arr);
            return arr[0].text;
          }else {
            var arr = that.codeSet[arg1].filter(item=>item.id === val);
//          console.log(val,arr);
              if(arr){
                  return arr[0].text;
              }else {
                  return "";
              }

          }

        }

      }
    },
    methods: {
        downloadFile(fileId,attachmentName) {
            var fileTypeArr = attachmentName.split(".");
            var fileType = fileTypeArr[fileTypeArr.length - 1].toLocaleLowerCase();
            if(fileType == 'pdf'){
                this.$router.push(
                  { name: 'excelView', query: {fileId:fileId}}
                );
            }else if(fileType == 'jpg'||fileType == 'png'||fileType == 'jpeg'||fileType == 'gif'||fileType == 'bmp'){
                this.images = [];
                this.previewShow = true;
                let baseUrl = contextRoot();
                var previewSrc = baseUrl+ '/api/file/att/download?fileId='+fileId.base64Encode()+'&app_userId='+getStore('user_id');
                this.images.push(previewSrc);
            }else {
                Dialog.alert({
                    title: '提示',
                    message: '附件类型不支持在线预览!',
                }).then(() => {
                    // on close
                });
            }
        },
      addZero(num){
        var addNum = num<10?"0"+num:num;
        return addNum;
      },
      datetimeSelect(value){
        this.show = false;
        var date = value;
          var val = date.getFullYear() + '-'+this.addZero(date.getMonth()+1) + '-'+ this.addZero(date.getDate());
        this.$set(this.datas,this.pickerName,val);
      },
      showpicker(event,name,title,code){
        if(code == 'getRetireData'){
          this.columns  = this.useTemp;
        }else {
          this.columns = this.codeSet[code];
        }

        this.pickershow = true;
        this.pickerName = name;
        this.title = title;
      },
      cancel() {
        this.show = false;
      },
      onConfirm(value){
        this.$set(this.datas,this.pickerName,value.id);
        this.pickershow = false;
        console.log(this.datas);
      },
      onCancel(){
        this.pickershow = false;
      },

      showdatepicker(event,name){
        this.show = true;
        this.pickerName = name;
      },
      saveData(msg) {
        if(this.opinion ==''){
          Toast({
            message:'必填项不能为空!',
            duration:'1000',
          });
          return;
        }
        Toast.loading({
          duration: 0,   // 持续展示 toast
          overlay: true,
          message: '正在提交...'
        });

        var data = {};
        data.app_userId = getStore('user_id');
        data.CHECK_TIME = new Date().getTime().toString();
        data.CHECK_SIGN = this.$md5(data.app_userId + data.CHECK_TIME + "3a28fba00c015e0df7f88556c91cb7fc");
        data.taskId = this.taskId;
        data.procInstanceId = Base64.encode(this.procInstId);
        data.msg = msg;
        data.opinion = this.opinion;
          console.log(data);
          submitApply(data).then(res => {
          Toast.clear();
              Dialog.alert({
                  title: '提示',
                  message: '审批成功！',
              }).then(() => {
                  this.$router.go(-1);
              });
        })
      },

    }
  }

</script>

<style lang="scss" scoped>
  @import '../../../assets/style/mixin';
  @import '../../../assets/style/public';

  .formContain {
    background: #fff;
    ul {
      padding: 0 .54rem;
      .flex {
        justify-content: space-between;
        align-items: center;
        line-height: 2rem;
        border-bottom: 1px solid #e0e0e0;
        padding: 0 .3rem;
        &:nth-last-of-type(1) {
          border: none;
        }
        .label {
          font-size: .56rem;
          line-height: 2rem;
          color: #333333;
        }
        div {
          display: flex;
          justify-content: flex-end;
          align-items: center;
          position: relative;
          flex-grow: 1;
          img {
            width: .68rem;
            height: .64rem;
          }
          input {
            color: #323233;
            text-align: right;
            font-size: .48rem;
            padding-right: .48rem;
            border: none;
            &:-ms-input-placeholder {
              color: #aaa;
              font-size: .48rem;

            }
          }
          .file {
            width: 2rem;
            height: 1rem;
            font-size: 10rem;
            opacity: 0;
            position: absolute;
            right: 0;
          }
          .van-cell {
            font-size: .48rem;
            padding-right: .48rem;
            padding: 0;
            color: #aaa;
            .van-field__control {
              color: #aaa;
            }
          }

        }
      }
    }
  }

  .foot-button {
    margin-top: 2rem;
    margin-bottom: .4rem;
    .cancel-btn {
      margin-right: 1rem;
    }
  }

  #datetime-picker, #picker {
    position: fixed;
    width: 100%;
    bottom: 0;
  }

  .require {
    color: red;
    margin-right: 4px;
    font-style: inherit;
    font-size: 14px;
  }
  .vtext{
    font-size: 0.48rem;
      text-align: right;
      line-height: 1rem;
  }
  .custom-button {
    width: 30px;
    color: #fff;
    font-size: 10px;
    line-height: 18px;
    text-align: center;
    background-color: #ee0a24;
    border-radius: 100px;
  }
</style>
